<?php
/**
 * Created by PhpStorm.
 * User: lzq
 * Date: 2018-11-9
 * Time: 17:05
 */

namespace backend\controllers;

use yii;
use yii\web\Controller;
use backend\models\SendEmail;
use backend\models\Goods;
use backend\models\User;
use mdm\admin\components\Helper;

class TestController extends Controller
{
    public function actionIndex(){
        //邮件
        $sendmail=new SendEmail();
        $send_info='';
        $sendmail->name='供货价管理系统';
        $sendmail->email=Yii::$app->params['adminEmail'];
        $sendmail->subject='有供货商创建新商品！';
        $sendmail->body="商品名称";
        if ($sendmail->sendEmail('408353018@qq.com')) {
           echo 'seccess';
        } else {
            echo 0;
        }
    }
    public function actionTest(){
        echo phpinfo();
    }
    public function actionSendsns(){
//        echo phpinfo();

        $arr = array(
            'userId'=>'J92599',
            'password'=>'688963',
            'pszMobis'=>'15901561351',
            'pszMsg'=>'您在供货价审批系统创建的1个商品已审核完成，详情请登录查看',
            'iMobiCount'=>count($gyslist),
            'pszSubPort'=>'0001',
            'MsgId'=>'',
        );

        set_time_limit(0);
//        $arr = array(
//            'userId'=>'J92599',
//            'password'=>'688963',
//            'pszMobis'=>'15901561351',
//            'pszMsg'=>'测试短信接口',
//            'iMobiCount'=>1,
//            'pszSubPort'=>'0001',
//            'MsgId'=>'',
//        );
//        $client=new \SoapClient('http://61.145.229.28:8806/MWGate/wmgw.asmx');
//        $result = $client->MongateSendSubmit($arr);
//        echo $result->MongateSendSubmitResult;
        $url="http://61.145.229.28:8806/MWGate/wmgw.asmx/MongateSendSubmit";
//        ?userId=J92599&password=688963&pszMobis=15901561351&pszMsg=测试短信接口&iMobiCount=1&pszSubPort=*&MsgId=123
//http://61.145.229.28:8806/MWGate/wmgw.asmx/MongateSendSubmit?userId=J92599&password=688963&pszMobis=15901561351&pszMsg=测试短信接口&iMobiCount=1&pszSubPort=*
        echo $this->doCurlPostRequest($url,http_build_query($arr));
    }
/*
**
*@desc 封闭curl的调用接口，get的请求方式。
*/
    function doCurlGetRequest($url,$data,$timeout = 5){
        if($url == "" || $timeout <= 0){
            return false;
        }
        $url = $url.'?'.http_build_query($data);
        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, false);
        curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout);

        return curl_exec($con);
    }
    /**
     ** @desc 封装 curl 的调用接口，post的请求方式
     **/
    function doCurlPostRequest($url,$requestString,$timeout = 5){
        if($url == '' || $requestString == '' || $timeout <=0){
            return false;
        }
        $aHeader = array('Content-Length: ' . strlen($requestString));
        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, $aHeader);
        curl_setopt($con, CURLOPT_POSTFIELDS, $requestString);
        curl_setopt($con, CURLOPT_POST,true);
        curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($con, CURLOPT_TIMEOUT,(int)$timeout);
        return curl_exec($con);
    }
    function actionClear(){
        Yii::$app->db->createCommand()->truncateTable('goods')->execute();//清空数据表 myii_stb
        Yii::$app->db->createCommand()->truncateTable('logs')->execute();//清空数据表 myii_stb
        echo "success";
        echo "<script>window.setTimeout(function(){window.location.href='/goods/index'},1000);</script>";
    }
}